package messages.registration;

import messages.BaseMessage;
import messages.MessageType;
import messages.MessageUtils;

public class PersonDispatcherRegistrationMessage extends BaseMessage {

    private int listenPort;
    
    public PersonDispatcherRegistrationMessage(byte[] data)
    {
        super(data);
        listenPort = MessageUtils.parseInt(data, 1);
    }
    
    public PersonDispatcherRegistrationMessage(int listenPort)
    {
        super(null);
        
        this.listenPort = listenPort;
    }

    @Override
    public byte[] toByteArray()
    {
        byte[] retVal = new byte[getMessageSize()];
        retVal[0] = getMessageType().getIdentifier();
        
        MessageUtils.insertInt(retVal, 1, listenPort);

    	return retVal;
    }

    @Override
    public MessageType getMessageType()
    {
        return MessageType.PersonDispatcherRegistrationMessage;
    }
    
    public int getListenPort()
    {
        return listenPort;
    }

    @Override
    public int getMessageSize()
    {
        return 5;
    }

}
